# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=cargo-edit
pkgver=0.12.3
pkgrel=1
pkgdesc="Managing cargo dependencies from the command line"
url="https://github.com/killercup/cargo-edit"
# s390x, ppc64le, riscv64: blocked by ring crate
# x86: tests segfault
arch="all !s390x !ppc64le !riscv64 !x86"
license="MIT OR Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	libgit2-dev
	libssh2-dev
	openssl-dev>3
	"
subpackages="$pkgname-doc"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/killercup/cargo-edit/archive/v$pkgver.tar.gz
	update-time-crate.patch
	fix-tests.patch
	"

export LIBSSH2_SYS_USE_PKG_CONFIG=1  # use system libssh2

# Exclude vendored-libgit2 feature.
_cargo_opts="--frozen --no-default-features --features add,rm,upgrade,set-version"

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	# Increase stack size to avoid stack overflow while compiling 'p384'.
	export RUST_MIN_STACK="4194304"

	cargo test $_cargo_opts
}

package() {
	install -Dm644 -t "$pkgdir/usr/share/doc/cargo-edit" README.md
	cd target/release
	install -Dm755 cargo-rm cargo-add cargo-set-version cargo-upgrade \
		-t "$pkgdir"/usr/bin/
}

sha512sums="
3e0f8a99b36adb225eba92dbab9c4c79a8c8247d4aa059949dae33bb267d991d774bf511564fd196ea0837f3262de44e3a09c40ec04f7cd4a68c96ba8decba07  cargo-edit-0.12.3.tar.gz
5049d675d61918243c8deaa9bd8661a368768783cef0ee73e78e73927c54446c5386adf393247a086839e8deb6f57336b017b4398c94db9d68b94755250dd745  update-time-crate.patch
54984dc87130044d60c6dec9025704b37e8c5383700f3e03abd8afdd043bdbc0e2e0d2ee2ec21965174e577f97ba378ccc2d0146cc055abde2da4b0fdd74b9dd  fix-tests.patch
"
